home *** CD-ROM | disk | FTP | other *** search
/ Games of Daze / Infomagic - Games of Daze (Summer 1995) (Disc 1 of 2).iso / x2ftp / msdos / mxcode / sbprocss / sinemix.pas < prev   
Pascal/Delphi Source File  |  1995-01-14  |  1KB  |  48 lines

  1. program SineMix; {$R-} {$S-} {$Q-}
  2.     uses
  3.         SBSample,
  4.         CRT;
  5.     const
  6.         WaveLength = 32; {In samples, freq varies depending on CPU speed}
  7.         Amplitude  = 8; {Keep it low to eliminate wave-top clipping}
  8.     var
  9.         Sines: array[0..WaveLength-1] of ShortInt;
  10.         Sample: byte;
  11.         x: word;
  12.     procedure InitSines;
  13.         var
  14.             i: word;
  15.         begin
  16.             for i := 0 to WaveLength-1 do
  17.                 Sines[i] := Round(Sin((2*Pi) * (i/WaveLength))*Amplitude);
  18.         end;
  19.     procedure ClipSample(var Sample: integer);
  20.         begin
  21.             if Sample > 127 then Sample := 127;
  22.             if Sample < -128 then Sample := -128;
  23.         end;
  24.     procedure ProcessSample(var Sample: byte);
  25.       {Make sure that you clip the sample so it stays in the proper range}
  26.         var
  27.             Temp: integer;
  28.         begin
  29.             Temp := Sample-128;
  30.  
  31.             {Process the sample here}
  32.             Temp := Temp*2+Sines[x];
  33.  
  34.             ClipSample(Temp);
  35.             Sample := Temp+128;
  36.         end;
  37.     begin
  38.         ResetDSP;
  39.         InitSines;
  40.         x := 0;
  41.         repeat
  42.             Sample := GetSample;
  43.             ProcessSample(Sample);
  44.             OutputSample(Sample);
  45.             Inc(x);
  46.             x := x mod WaveLength;
  47.         until KeyPressed; ReadKey;
  48.     end.